package com.shoponline.dao.hibernate;

import org.hibernate.Session;

import com.shoponline.dao.DAOFactory;
import com.shoponline.dao.UserDAOTest;
import com.shoponline.util.HibernateUtil;

public class HibernateDAOFactory extends DAOFactory {

	@Override
	public UserDAOTest getUserDAO() {

		
		return (UserDAOTest) instantiateDAO(UserDAOHibernate.class);

	}

	private GenericHibernateDAO instantiateDAO(Class daoClass) {

		try {
			GenericHibernateDAO dao = (GenericHibernateDAO) daoClass.newInstance();
			dao.setSession(getCurrentSession());
			System.out.println("instantiate DAO:"+daoClass);
			return dao;
		} catch (Exception ex) {
			System.out.println("instantiateDAO:"+daoClass);
			throw new RuntimeException("Can not instantiate DAO: " + daoClass,
					ex);
		}
	}

	// You could override this if you don't want HibernateUtil for lookup
	protected Session getCurrentSession() {
		System.out.println("getCurrentSession...");
		return HibernateUtil.getSession();
	}

}
